package com.fish.service.impl.passport;

import java.util.Date;

import com.fish.passport.po.PassCode;
import com.fish.passport.po.PassEvent;
import com.fish.passport.po.PassPortCode;
import com.fish.service.passport.ProcessorCallbackService;
import com.fish.vo.Passport;
import com.fish.vo.PassportConstant;

/**
 * 废码回调实现
 * 
 * @author chenlinjun
 * @date:2010-9-25
 */
public class DestroyCodeProcessorCallbackServiceImpl extends ProcessorCallbackService {
	@Override
	public boolean successExecute(PassCode passCode, Passport passport) {
		PassEvent event = new PassEvent();
		event.setCodeId(passCode.getCodeId());
		event.setType(PassportConstant.PASSCODE_TYPE.DESTROYCODE.name());
		event.setStatus(PassportConstant.PASSCODE_STATUS.SUCCESS.name());
		passEventDAO.updateEventStauts(event);
		
		// 设置废码状态
		passCode.setStatus(PassportConstant.PASSCODE_USE_STATUS.DESTROYED.name());
		passCode.setUpdateTime(new Date());
		passCode.setStatusNo(null);
		passCode.setStatusExplanation(null);
		passCodeDAO.updatePassCode(passCode);
		
		//通关码全部废掉
		PassPortCode passPortCode =new PassPortCode();
		passPortCode.setCodeId(passCode.getCodeId());
		passPortCode.setStatus(PassportConstant.PASSCODE_USE_STATUS.DESTROYED.name());
		passPortCodeDAO.updatePassPortCodeByCodeId(passPortCode);
		return true;
	}
	
	@Override
	protected boolean errorExecute(PassCode passCode, Passport passport, PassEvent passEvent) {
		passEvent.setStatus(PassportConstant.PASSCODE_STATUS.FAILED.name());
		passEventDAO.updateEventStauts(passEvent);
		super.addComLog(passCode, passport.getComLogContent(), "废除通关码失败");
		return false;
	}
}
